<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
   <meta charset="UTF-8">
   <%@ include file="/WEB-INF/views/include/head.jsp"%>
   <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
   <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
   <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
   <script src="${ctxStatic}/js/layer.js"></script>
   <script src="${ctxStatic}/js/style.js"></script>
   <script src="${ctxStatic}/jquery-barcode/jquery-barcode.js" type="text/javascript"></script>
   <c:set value="<%=ResourcesUtil.getConfig(\"inventory_status_not_all\")%>" var="inventoryStatusNotAll" />
   <c:set value="<%=ResourcesUtil.getConfig(\"inventory_status_all\")%>" var="inventoryStatusAll" />
   <script type="text/javascript">
      $(document).ready(function(){
    	 var imageStr = '${imageStr}';
    	 if (imageStr == 'customizationUnitCost'){
  			var productionID = $("#contractID").find("option:selected").attr("pId-value");
  	    	var productionNo = $("#contractID").find("option:selected").attr("pNo-value");
  	    	$("#productionID").val(productionID);
  	    	$("#productionNoText").text(productionNo);
  		 }
    	 $("#contractID").select2();
    	 $("#contractID").attr("disabled",true);
         $("#inventoryRequestBarCodeDiv").empty().barcode($("#stockBarCode").val(), "code128",{barWidth:2, barHeight:30,showHRI:false});
      });
      
      /* 刷新明细  */
      function requestDetails() {
    	  var id ="${inventoryRequestEx.id}";
      	param={"id":id};
      	$.post("${ctx}/material/inbound/show",param,function(result){ 
          	$("#tableRequestDetails").html($(callBackHtml(result)).find("#tableRequestDetails").html());
          	tryToCgStatus();
          },'html');
  	}
      /* 试图更改入库状态  */
      function tryToCgStatus() {
		var length = $(".realQuantity").length;
		var sumResult = parseFloat(0);
		for (var i = 0; i < length; i++) {
			var realQuantity = $(".realQuantity")[i].innerHTML;
			if (realQuantity==""||realQuantity==null) {
				return;
			}
			realQuantity = realQuantity.replace(/,/g,"");
			sumResult += parseFloat(realQuantity);
		}
		var requestQuantity = "${inventoryRequestEx.requestQuantity}";
		requestQuantity = parseFloat(requestQuantity.replace(/,/g,""));
		if (requestQuantity>sumResult) {
			var inventoryStatus = "${inventoryStatusNotAll}";
		}else if(requestQuantity<=sumResult){
			var inventoryStatus = "${inventoryStatusAll}";
		}
		var id = "${inventoryRequestEx.id}";
		var params = {"id":id,"inventoryStatus":inventoryStatus};
		$.post("${ctx}/material/inbound/changeStatus",params,function(result){    
			window.parent.frames[0].searchListForm();
          },'html');
	}
   // 导出
  	function exportUnit() {
	   var contractNo = $("#contractID").find("option:selected").text();
  		//$("#activity_pane").showLoading();
  		window.location.href='${ctx}/inventory/requestex/exportFile?inventoryDetailId=${inventoryRequestEx.id}&contractNo='+contractNo;
  		//$("#activity_pane").hideLoading();
  	}
  	 //格式化金额
    function formatMoneyThis(e, n) {  
    	var s=$(e).text().replace(",","").trim();
    	//判断字符串是否为数字     //判断正整数 /^[1-9]+[0-9]*]*$/  
    	var numberVerification = /^[0-9]+.?[0-9]*$/;   
        if (numberVerification.test(s)){
        	n = n > 0 && n <= 20 ? n : 2;  
            s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";  
            var l = s.split(".")[0].split("").reverse(), r = s.split(".")[1];  
            t = "";  
            for (var i = 0; i < l.length; i++) {  
                t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");  
            } 
            $(e).text(t.split("").reverse().join("") + "." + r);
        }else{
        	$(e).text("");
        }
    }  
	</script>
</head>
<body>
<div class="layerHeader clearfix">
	<p class="headerTitle"><spring:message code="inventory_requestex_create_materialInventory"/></p>
    <div class="headerButton clearfix">
    <c:if test="${imageStr == 'customizationUnitCost' }">
    	<!-- 导出 -->
		<button type="button" class="btn-js"  onclick="exportUnit();"><spring:message code="common_export"/></button>
    </c:if>
    <!-- 编辑 -->
        <button onclick="window.location.href='${ctx}/inventory/requestex/form?id=${inventoryRequestEx.id}'"><spring:message code="inventory_requestex_create_editBtn"/></button>
        <!-- 取消 -->
        <button onclick="closeWin()"><spring:message code="btn_cancle"/></button>
    </div>
</div>
<div class="smOrderBox">
    <div class="items clearfix">
        <div class="col-33 clearfix">
            <!-- 出库单号 -->
            <p class="tit"><spring:message code="inventory_requestex_create_requestNo"/></p>
            <p>${inventoryRequestEx.inventoryRequestNo}</p>
        </div>
        <div class="col-33 clearfix">
            <!-- 申请人 -->
            <p class="tit" style="width: 60px;"><spring:message code="inventory_requestex_create_requestUser"/></p>
            <p>${inventoryRequestEx.requestUser}</p>
        </div>
        <div class="col-33 clearfix">
            <!-- 申请日期 -->
            <p class="tit" style="width: 60px;"><spring:message code="inventory_requestex_create_requestDate"/></p>
            <p><fmt:formatDate value="${inventoryRequestEx.requestDate}" pattern="yyyy-MM-dd" /></p>
        </div>
    </div>
    <div class="items clearfix">
        <c:if test="${imageStr == 'customizationUnitCost' }">
        <div class="col-33 clearfix haveToBox">
		    <!-- 定制合同号 -->
		    <p class="tit"><spring:message code="unitCost_export_select_contractNo"/></p>
			<div class="timeBox">
				<select id="contractID" name="contractID" style="width: 180px;" onchange="getCoMaterialList();">
					<option value=""><spring:message code="unitCost_export_select_pleaseChoose"/></option>
					<c:forEach items="${contractList }" var="ct">
						<option value="${ct.contractID }" pId-value="${ct.productionID }" pNo-value="${ct.productionNo }" <c:if test="${inventoryRequestEx.contractID == ct.contractID }">selected="selected"</c:if>>${ct.contractNo }</option>
					</c:forEach>
				</select> 
			</div>
        </div>
        </c:if>
        <div class="col-50 clearfix">
            <!-- 出库类别 -->
            <p class="tit"><spring:message code="inventory_requestex_create_inventoryCategory"/></p>
            <p>${fns:getDictName(inventoryRequestEx.inventoryCategory)}</p>
        </div>
    </div>
    <c:if test="${imageStr eq 'produceNotice' }">
    <div class="items clearfix">
        <div class="col-33 clearfix">
            <!-- 客户名称-->
            <p class="tit"><spring:message code="inventory_requestex_create_customerName"/></p>
            <p>${inventoryRequestEx.venderName}</p>
        </div>
        <div class="col-33 clearfix">
            <!-- 客户订单号 -->
            <p class="tit" style="width: 75px;"><spring:message code="inventory_requestex_create_indentNo"/></p>
            <p>${inventoryRequestEx.indentNo}</p>
        </div>
        <div class="clearfix">
            <!-- 款号/名称 -->
            <p class="tit"><spring:message code="inventory_requestex_create_styleNoName"/></p>
            <p>${inventoryRequestEx.styleCustomerNo}&ensp;${inventoryRequestEx.styleName}</p>
        </div>
    </div>
    </c:if>
</div>
<div class="tableArea">
    <div class="tableScrollSm" <c:if test="${imageStr == 'customizationUnitCost' }">style="overflow:auto;width:853px;height:440px;"</c:if><c:if test="${imageStr != 'customizationUnitCost' }">style="overflow:auto;width:853px;height:400px;"</c:if>>
        <table cellpadding="0" class="tableHead">
            <thead>
            <tr>
                <!-- 操作 -->
                <th style="width:50px;"><spring:message code="inventory_requestex_create_details_operate"/></th>
                <!-- 物料图片 -->
                <th class="tab-wltp"><spring:message code="inventory_requestex_create_details_img"/></th>
                <!-- 名称编码 -->
                <th><p class="tab-wlmcbj"><spring:message code="inventory_requestex_create_details_nameCode"/></p></th>
                <!-- 物料类别 -->
                <th><p class="width-80px"><spring:message code="inventory_requestex_create_details_materialCategory"/></p></th>
                <!-- 颜色 -->
                <th><p class="width-80px"><spring:message code="inventory_requestex_create_details_color"/></p></th>
                <!-- 成分 -->
                <th><p class="width-80px"><spring:message code="inventory_requestex_create_details_composition"/></p></th>
                <!-- 幅宽 -->
                <th><p class="width-80px"><spring:message code="inventory_requestex_create_details_spec"/></p></th>
                <!-- 库存数量 -->
                <th class="width-120px"><spring:message code="inventory_requestex_create_details_materialQuantity"/></th>
                <!-- 申请出库数量 -->
                <th class="width-120px"><spring:message code="inventory_requestex_create_details_requestQuantity"/></th>
            </tr>
            </thead>
        </table>
        <table cellpadding="0" class="tableBody" id="tableRequestDetails">
            <tbody>
        <c:if test="${not empty inventoryRequestEx.requestDetailsList}">
            <c:forEach items="${inventoryRequestEx.requestDetailsList}" var="requestDetailsInfo" varStatus="status">
            <tr>
                <td style="width:50px;"></td>
                <td class="tab-wltp">
                  <c:if test="${not empty requestDetailsInfo.filePath}">
                        <img src="${requestDetailsInfo.filePath}" class="wltp">
                  </c:if>
                  <c:if test="${empty requestDetailsInfo.filePath}">
                        <img src="${ctxStatic}/images/pic-none.jpg" class="wltp">
                  </c:if>
                </td>
                <td><p class="tab-wlmcbj"><c:if test="${imageStr != 'customizationUnitCost' }">${requestDetailsInfo.materialNameCn}<br></c:if>${requestDetailsInfo.materialCode}</p></td>
                <td><p class="width-80px">${fns:getDictName(requestDetailsInfo.materialCategory)}</p></td>
                <td><p class="width-80px">${requestDetailsInfo.materialColor}</p></td>
                <td><p class="width-80px">${requestDetailsInfo.materialComposition}</p></td>
                <td><p class="width-80px">${requestDetailsInfo.materialSpec}</p></td>
                <td class="qt1 subDetails width-120px"><p class="textRight"><fmt:formatNumber value="${requestDetailsInfo.materialQuantity}" pattern="#,##0.00#"/></p></td>
                <td class="qt2 subDetails width-120px realQuantity"><p class="textRight"><fmt:formatNumber value="${requestDetailsInfo.requestQuantity}" pattern="#,##0.00#"/></p></td>
            </tr>
            </c:forEach>
            </tbody>
            </c:if>
        </table>
    </div>
</div>
</body>
</html>